#!/usr/bin/env python
# -*- coding: utf-8 -*-
#       
#       Copyright 2010 Santiago Lezica, Juan Pablo Orsay, Facundo Martinez.
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

# We have to remove this, obviously. This adds the project directory to the
# system path, so that the modules are found by absolute reference:
import sys, os
sys.path.append(os.path.abspath("../.."))

#from carcassonne.dummies import DummyCodec, DummyMasterHandler

from carcassonne.codecs.jsoncodec import JSONCodec
from carcassonne.modscan import ModuleScanner
from carcassonne.model import Handler, Message

from carcassonne.server.protocol import ServerFactory
from carcassonne.dispatcher import DispatcherHandler

from twisted.internet import reactor

# INITIAL SET-UP. Creating and connecting the components:
messages = ModuleScanner.getSubclassesOf("carcassonne.messages", Message)
handlers = ModuleScanner.getSubclassesOf("carcassonne.server.handlers", Handler)

codec = JSONCodec()
handler = DispatcherHandler()
factory = ServerFactory()

handler.config(comm = factory,
               codec = codec,
               dao = None,
               messages = messages,
               handlers = handlers)

factory.config(handler = handler)

# All set. Go!

reactor.listenTCP(4040, factory)
reactor.run()
